package com.engine.jucailinkq.attendance.attendanceanalysis.cmd.item;

import com.engine.jucailinkq.attendance.enums.AttendanceItemTypeEnum;
import com.engine.jucailinkq.attendance.enums.WorkForTimeEnum;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import lombok.extern.slf4j.Slf4j;
import weaver.general.Util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
public class ForGetClockItemCmd extends AbstractCommonCommand<Map<String,Object>> {
    @Override
    public BizLogContext getLogContext() {
        return null;
    }
    public ForGetClockItemCmd(Map<String,Object> params){
        this.params=params;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        //作用时段
        String workfor = Util.null2String(params.get("workfor"));
        //项目id
        String key = Util.null2String(params.get("key"));
        Map<String, Object> resultMap = new HashMap<>();

        List<Map<String,Object>> attendanceItems = (List<Map<String,Object>>)params.get("attendanceItems");
        attendanceItems = attendanceItems.stream().filter(e -> {
            //项目类型
            String xmlx = Util.null2String(e.get("xmlx"));
            //作用时段
            String zysd = Util.null2String(e.get("zysd"));
            //项目id
            String id = Util.null2String(e.get("key"));

            if(AttendanceItemTypeEnum.OTHER.getKey().equals(xmlx) && (zysd.contains(workfor) || zysd.contains(WorkForTimeEnum.ALL_TIME.getKey())) && key.equals(id)) {
                return true;
            }else {
                return false;
            }
        }).collect(Collectors.toList());
        log.debug("ForGetClockItemCmd attendanceItems : [{}]",attendanceItems);
        resultMap.put("attendanceItems",attendanceItems);

        return resultMap;
    }
}
